package com.webkitlib.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.content.Intent;
import android.net.Uri;

public class KpaiZ {
    public String theLarge;
    public static String SAVED_IMAGE_DIR_PATH = KFileUitl.getSDPath() + File.separator + "kHan"
                    + File.separator + "img" + File.separator;

    public static String SAVED_TXT_DIR_PATH = KFileUitl.getSDPath() + File.separator + "kHan"
                    + File.separator + "Log" + File.separator;

    public Intent pai(String path) {
        if (!(path.equals(""))) {
            SAVED_IMAGE_DIR_PATH = path;
        }
        Intent intents = phone_();
        return intents;
    }

    public Intent pai() {
        Intent intents = phone_();
        return intents;
    }

    private Intent phone_() {
        long dates = System.currentTimeMillis();
        String out_file_path = SAVED_IMAGE_DIR_PATH;
        KLoger.d("==图片地址==", out_file_path);
        String dates_image = dates + ".jpg";
        File f = new File(out_file_path);
        if (!(f.exists())) {
            f.mkdirs();
        }
        File phoneFile = new File(f.getAbsolutePath() + "/" + dates_image);
        if (!(phoneFile.exists())) {
            try {
                phoneFile.createNewFile();
                KLoger.d("==图片地址==", "创建地址成功-->>");
            } catch (IOException e) {
                KLoger.d("==图片地址==", "创建地址失败-->>");
                e.printStackTrace();
            }
        }
        Uri uri = Uri.fromFile(phoneFile);
        KLoger.d("==图片地址==", "uri地址信息-->>" + uri);
        this.theLarge = out_file_path + dates_image;
        Intent intents = new Intent();
        intents.setAction("android.media.action.IMAGE_CAPTURE");
        intents.putExtra("output", uri);
        return intents;
    }

    public static void writelog(String log) {
        File f = new File(SAVED_IMAGE_DIR_PATH);
        if (!(f.exists())) {
            f.mkdirs();
        }
        File txtfile = new File(f.getAbsolutePath() + "/" + "han_log.txt");
        if (!(txtfile.exists()))
            try {
                txtfile.createNewFile();
                KLoger.d("==txt文件==", "创建地址成功-->>");
            } catch (IOException e) {
                KLoger.d("==txt文件==", "创建地址失败-->>");
                e.printStackTrace();
            }
        try {
            FileOutputStream fos = new FileOutputStream(txtfile);
            fos.write(log.getBytes());
            fos.close();
            KLoger.d("==txt文件==", "写入成功-->>");
        } catch (IOException e) {
            KLoger.d("==txt文件==", "写入失败-->>");
            e.printStackTrace();
        }
    }
}
